<?xml version="1.0"?>
<Model name="euclid">

  <TypeDef name="uint16" type="unsigned" width="16"/>
  <TypeDef name="uint32" type="unsigned" width="32"/>
	
	<Module name="simple">
	<Datapath>
		<!-- Connectors -->
		<Connector name="a_in" kind="queue" direction="in" type="uint16"/>
		<Connector name="b_in" kind="queue" direction="in" type="uint16"/>
		<Connector name="c_out" kind="queue" direction="out" type="uint16"/>
										
		<!-- <Queue name="inc_input" type="uint16"/> -->
		<Queue name="output" type="uint16"/>
		<Signal name="dec_output" type="uint16"/>
		<Signal name="tmp" type="uint16"/>
		
		<Use name="incrementer" entity="inc">
			<Connect connector="input" channel="a_in"/>
			<Connect connector="output" channel="output"/>
		</Use>
		
		<Use name="decrementer" entity="dec">
			<Connect connector="input" channel="tmp"/>
			<Connect connector="output" channel="dec_output"/>
		</Use>
										
		<SignalFlowGraph name="run">		
			<Expression>
				c_out = dec_output;
			</Expression>		
			<Expression>
				tmp = output + b_in;
			</Expression>
			<Expression>
				$display("adding values");
			</Expression>			
		</SignalFlowGraph>		
		
		</Datapath>
		<Controller>
		<State name="s0" initial="true"/>	
		<State name="s1"/>

		<TransitionSet source="s0">		
			<Wait target="s1">
				<QueueReadyEvent name="output"/>
				<QueueReadyEvent name="b_in"/>
			</Wait>
		</TransitionSet>
		
		<TransitionSet source="s1">		
			<Transition target="s0">			
				<ExecutionSet>
					<SignalFlowGraphRef name="run"/>				
				</ExecutionSet>
			</Transition> 			
		</TransitionSet>					
					
	</Controller>
	</Module>
	
	<Module name="dec">
	<Datapath>
		<Connector name="input" kind="port" direction="in" type="uint16"/>
		<Connector name="output" kind="port" direction="out" type="uint16"/>
		
		<SignalFlowGraph name="run">
			<Expression>
				output = input - 1;
			</Expression>
			<Expression>
				$display("decrementing value");
			</Expression>			
		</SignalFlowGraph>		
	</Datapath>
	
	<Controller>
		<State name="s0" initial="true"/>					
		<TransitionSet source="s0">
			<Transition target="s0">
				<ExecutionSet>
					<SignalFlowGraphRef name="run"/>
				</ExecutionSet>
			</Transition>
		</TransitionSet>		
	</Controller>
	</Module>
	
	<Module name="inc">
	<Datapath>
		<Connector name="input" kind="queue" direction="in" type="uint16"/>
		<Connector name="output" kind="queue" direction="out" type="uint16"/>
		
		<SignalFlowGraph name="run">
			<Expression>
				output = input + 1;
			</Expression>
			<Expression>
				$display("incrementing value");
			</Expression>			
		</SignalFlowGraph>		
	</Datapath>
	
	<Controller>
		<State name="s0" initial="true"/>
		<State name="s1"/>
		
		<TransitionSet source="s0">		
			<Wait target="s1">
				<QueueReadyEvent name="input"/>
			</Wait>
		</TransitionSet>	
		
		<TransitionSet source="s1">
			<Transition target="s0">
				<ExecutionSet>
					<SignalFlowGraphRef name="run"/>
				</ExecutionSet>
			</Transition>
		</TransitionSet>		
	</Controller>
	</Module>
	
	<Module name="test_simple">
	<Datapath>
		<Connector name="a_out" kind="queue" direction="out" type="uint16"/>
		<Connector name="b_out" kind="queue" direction="out" type="uint16"/>
		<Connector name="c_in"  kind="queue" direction="in"  type="uint16"/>
		
		<Register name="count" type="uint32"/>
		
		<SignalFlowGraph name="sfg1">
			<Expression>
				count = count + 1;
			</Expression>
			<Expression>
				a_out = count + 6;		
			</Expression>
			<Expression>
				$display("a_out: ", a_out);		
			</Expression>
			<Expression>
				b_out = 3;				
			</Expression>
			<Expression>
				$display("b_out: ", b_out);
			</Expression>
			<Expression>
				$display("writing test values");
			</Expression>			
		</SignalFlowGraph>				
		
		<SignalFlowGraph name="sfg2">
			<Expression>
				$display("result (c_in): ", c_in);
			</Expression>
		
		</SignalFlowGraph>				
	</Datapath>

	<Controller>
		<State name="s0" initial="true"/>
		<State name="s1"/>
		<State name="s2"/>
				
		<TransitionSet source="s0">			
			<Transition target="s1">
				<ExecutionSet>
			 		<SignalFlowGraphRef name="sfg1"/>			 
				</ExecutionSet>	
			</Transition>
		</TransitionSet>				
				
		<TransitionSet source="s1">		
			<Wait target="s2">
				<QueueReadyEvent name="c_in"/>
			</Wait>
		</TransitionSet>	
													
		<TransitionSet source="s2">				
			<Transition target="s0">
				<ExecutionSet>
				 	<SignalFlowGraphRef name="sfg2"/>			 
				</ExecutionSet>					
			</Transition>									
		</TransitionSet>				
			
	</Controller>
	</Module>
	
	
	<System name="S">
		<!-- connection name is optional -->
		<Queue name="a" type="uint16"/>
		<Queue name="b" type="uint16"/>
		<Queue name="c" type="uint16"/>
		
		<Use name="SIMPLE" entity="simple">
			<Connect connector="a_in"  channel="a"/>
			<Connect connector="b_in"  channel="b"/>
			<Connect connector="c_out" channel="c"/>
		</Use>
		
		<Use name="TEST_SIMPLE" entity="test_simple">
			<Connect connector="a_out" channel="a"/>
			<Connect connector="b_out" channel="b"/>
			<Connect connector="c_in"  channel="c"/>
		</Use>				
	</System>
</Model>
